LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.all;
USE IEEE.STD_LOGIC_UNSIGNED.all;
USE WORK.ic_5;

--TESTBENCH DO IC_5(JKFF)

ENTITY tb_ic_5_jkff IS
END tb_ic_5_jkff;

ARCHITECTURE logic OF tb_ic_5_jkff IS

COMPONENT ic_5
    PORT(pin1, pin4, pin8, pin9, pin10, pin11, pin12, pin13 :IN STD_LOGIC; 
        pin2, pin3, pin5, pin6:OUT STD_LOGIC);
END COMPONENT;

SIGNAL s_j, s_k, s_clr, s_clk, s_q, s_nq: STD_LOGIC;

FOR jkff_test: ic_5 USE ENTITY WORK.ic_5(jkff_ic);

BEGIN
    jkff_test: ic_5
    PORT MAP(pin1=>s_j, pin2=>s_pin2, pin4=>s_pin4, pin5=>s_pin5, pin6=>s_pin6,
        pin8=>s_pin8, pin9=>s_pin1, pin10=>s_pin2, pin12=>s_pin4, pin13=>s_pin5); 
    PROCESS
        TYPE pattern_record IS RECORD
            vi_pin1, vi_pin2, vi_pin4, vi_pin5, vo_pin6, vo_pin8: STD_LOGIC;
        END RECORD;
        TYPE pattern_tests IS ARRAY (NATURAL RANGE <>) OF pattern_record;
            CONSTANT patterns : pattern_tests :=
            (
                ('0', '0', '0', '0', '1', '1'),
                ('1', '0', '0', '0', '1', '1'),
                ('0', '1', '0', '0', '1', '1'),
                ('1', '1', '0', '0', '1', '1'),
                ('0', '0', '1', '0', '1', '1'),
                ('1', '0', '1', '0', '1', '1'),
                ('0', '1', '1', '0', '1', '1'),
                ('1', '1', '1', '0', '1', '1'),
                ('0', '0', '0', '1', '1', '1'),
                ('1', '0', '0', '1', '1', '1'),
                ('0', '1', '0', '1', '1', '1'),
                ('1', '1', '0', '1', '1', '1'),
                ('0', '0', '1', '1', '1', '1'),
                ('1', '0', '1', '1', '1', '1'),
                ('0', '1', '1', '1', '1', '1'),
                ('1', '1', '1', '1', '0', '0')
            );
    BEGIN
        FOR i IN patterns'RANGE LOOP
				s_pin1 <= patterns(i).vi_pin1;
				s_pin2 <= patterns(i).vi_pin2;
				s_pin4 <= patterns(i).vi_pin4;
				s_pin5 <= patterns(i).vi_pin5;

            WAIT FOR 100 ps;
				ASSERT s_pin6 = patterns(i).vo_pin6 REPORT "VALOR DO PINO 6 ERRADO" SEVERITY error;
				ASSERT s_pin8 = patterns(i).vo_pin8 REPORT "VALOR DO PINO 8 ERRADO" SEVERITY error;
        END LOOP;
        ASSERT false REPORT "END." SEVERITY note;
        WAIT;
    END PROCESS;
END logic;
